package cappuccino.couldbook.ui.Adapter;

import android.content.Context;
import android.support.design.widget.TextInputLayout;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;

import cappuccino.couldbook.App;
import cappuccino.couldbook.R;

/**
 * Created by Administrator on 2016/9/12.
 */
public class RecylerInputAdapter extends RecyclerView.Adapter<RecylerInputAdapter.InputViewHolder> {

    String[] tags;
    Context context;
    InputViewHolder[] holders;

    public RecylerInputAdapter(Context context,String... tags) {
        this.tags = tags;
        this.context = context;
        holders = new InputViewHolder[tags.length];
    }

    @Override
    public InputViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        InputViewHolder holder;
        holder = new InputViewHolder(LayoutInflater.from(context).inflate(R.layout.item_input, parent, false));
        return holder;
    }

    @Override
    public void onBindViewHolder(InputViewHolder holder, int position) {
        holders[position] = holder;
        holder.setTag(tags[position]);
    }

    @Override
    public int getItemCount() {
        return tags.length;
    }

    public String [] getInputs(){
        String [] inputs = new String[holders.length];
        for (int i=0;i<holders.length;i++) {
            inputs[i] =  holders[i].getText();
        }
        return inputs;
    }

    class InputViewHolder extends RecyclerView.ViewHolder {

        TextInputLayout input;
        public InputViewHolder(View itemView) {
            super(itemView);
            input = (TextInputLayout) itemView.findViewById(R.id.til_input);
        }

        public void setTag(String tag){
            Log.v("set tag","Tag:"+tag);
            input.setHint(tag);
        }

        public String getText(){
            return input.getEditText().getText().toString();
        }
    }
}
